package com.weilive.push.service.apns;

import com.notnoop.apns.ApnsDelegate;
import com.notnoop.apns.ApnsNotification;
import com.notnoop.apns.DeliveryError;
import com.notnoop.apns.internal.Utilities;
import com.notnoop.exceptions.ApnsDeliveryErrorException;

public class ApnsDelegateImpl implements ApnsDelegate {

	@Override
	public void messageSendFailed(ApnsNotification message, Throwable e) {
		if (message != null) {
			// 失效的token不在重发
			if (e instanceof ApnsDeliveryErrorException) {
				ApnsDeliveryErrorException e1 = (ApnsDeliveryErrorException) e;
				if (e1.getDeliveryError() == DeliveryError.INVALID_TOKEN) {
					ApnsInactiveDevice.addInactiveDevice(Utilities.encodeHex(message.getDeviceToken()).toLowerCase());
				}
			}
		}
	}

	@Override
	public void connectionClosed(DeliveryError e, int messageIdentifier) {
		// token失效
	}

	protected void logException(Exception ex, Long logRecordId) {
	}

	@Override
	public void messageSent(ApnsNotification message, boolean resent) {
	}

	@Override
	public void cacheLengthExceeded(int newCacheLength) {
	}

	@Override
	public void notificationsResent(int resendCount) {
	}

}
